package o;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.RemoteBuoyAction;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appmarket.service.activitydispatcher.OpenGateway;
import com.huawei.appmarket.service.activitydispatcher.OpenGateway$c;
import o.cii.c;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class dpa implements c {
    private static JSONObject ˎ(String str) {
        Object obj = "";
        if (!TextUtils.isEmpty(str)) {
            int indexOf = str.indexOf(124);
            if (indexOf != -1) {
                obj = str.substring(indexOf + 1);
            }
        }
        if (!TextUtils.isEmpty(obj)) {
            try {
                return new JSONObject(obj);
            } catch (Throwable e) {
                Logger.ˋ("CardEventActivityListener", "parse json error, detailID:" + str, e);
            }
        }
        return null;
    }

    public void ˏ(Context context, BaseCardBean baseCardBean) {
        if (context != null && (context instanceof Activity)) {
            JSONObject ˎ = ˎ(baseCardBean.ॱॱ());
            if (ˎ != null) {
                Object obj = "";
                try {
                    obj = ˎ.getString("activityName");
                } catch (JSONException e) {
                    Logger.ˎ("CardEventActivityListener", "createIntent, get activityName JSONException:" + e);
                }
                Logger.ˎ("CardEventActivityListener", "createIntent, activity:" + obj);
                if (!TextUtils.isEmpty(obj)) {
                    JSONArray jSONArray = null;
                    try {
                        jSONArray = ˎ.getJSONArray(RemoteBuoyAction.REMOTE_BUOY_PARAM);
                    } catch (JSONException e2) {
                        Logger.ˎ("CardEventActivityListener", "createIntent, get params JSONException:" + e2);
                    }
                    OpenGateway$c ˎ2 = OpenGateway.ˎ(obj, jSONArray, false);
                    if (ˎ2 == null) {
                        return;
                    }
                    if (ˎ2.ˎ() != null) {
                        cjk.ˎ().ˋ(context, ˎ2.ˎ());
                    } else if (ˎ2.ˏ() != null) {
                        context.startActivity(ˎ2.ˏ());
                    } else if (ˎ2.ˊ() != null) {
                        OpenGateway$c.c ˊ = ˎ2.ˊ();
                        fiu.ˊ().ॱ(context, ˊ.ˋ, ˊ.ˏ);
                    } else {
                        Logger.e("CardEventActivityListener", "can not start target activity.Go MainActivity");
                    }
                }
            }
        }
    }
}
